package com.gi.product.message;

import com.gi.product.dto.CartDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * Created by lancf on 2019/7/11.
 */
@Component
@Slf4j
public class MqMessageRecive {


    //第一种方式需手动创建Queue @RabbitListener(queues="myqueue")
    //第二种方式会自动创建Queue @RabbitListener(queuesToDeclare = @Queue("myqueue"))
    @RabbitListener(queuesToDeclare = @Queue("myqueue"))
    public void bb(String msg) {
        log.info("监听到的消息{}", msg);
    }

    //第三种方式Queue与exchange绑定
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("myQueue2"),
            exchange = @Exchange("myExchange")
    ))
    public void cc(String msg) {
        log.info("监听到的消息{}", msg);
    }

    //第四种方式 分组
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("computerQueue"),
            key = "computer",
            exchange = @Exchange("myOrder")
    ))
    public void computer(String msg) {
        log.info("监听到的消息-->computer= {}", msg);
    }


    //第四种方式 分组
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("furitQueue"),
            key = "furit",
            exchange = @Exchange("myOrder")
    ))
    public void furit(String msg) {
        log.info("监听到的消息-->furit= {}", msg);
    }
}
